# -*- codeing = utf-8 -*-
print('''
# @Time : 2021/12/8 08:04
# @Autor: 李帅兵 
# @File : main.py
# @Software：PyCharm
''')
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

wd = webdriver.Chrome()
Account = ""
Password = ""
with open('Account&Password', 'r', encoding='utf-8') as f:
    A_P = f.readlines()
    Account = A_P[0].split(':')[1].replace('\n', '')
    Password = A_P[1].split(':')[1]
print('正在登陆请确认你的用户名及密码')
print(Account)
print(Password)
wd.get('https://jwgln.zsc.edu.cn/jsxsd/')
try:
    wd.find_element(By.XPATH, '//*[@id="userAccount"]').send_keys(Account)
    wd.find_element(By.XPATH, '//*[@id="userPassword"]').send_keys(Password)
except Exception:
    print('账户密码错误')
    exit()
print('已成功进入教务网')
time.sleep(0.1)
wd.find_element(By.XPATH, '//*[@id="btnSubmit"]').click()
time.sleep(0.1)
wd.find_element(By.XPATH, '/html/body/div[6]/a[2]/div').click()
time.sleep(1)
wd.find_element(By.XPATH, '//*[@id="Form1"]/table/tbody/tr[2]/td[7]/a').click()
time.sleep(1)
tr_list = wd.find_elements(By.XPATH, '//*[@id="dataList"]/tbody/tr')
for tr_ in tr_list:
    print('开始评教')
    try:
        tr_.find_element(By.XPATH, './td[8]/a').click()
    except Exception:
        continue
    n = wd.window_handles  # 这个时候会生成一个新窗口或新标签页的句柄，代表这个窗口的模拟driver
    wd.switch_to_window(n[-1])  # driver切换至最新生产的页面
    tr_lib = wd.find_elements(By.XPATH, '//*[@id="table1"]/tbody/tr')
    time.sleep(1)
    for tr in tr_lib:
        try:
            tr.find_element(By.XPATH, './td[2]/input[7]').click()
        except Exception:
            pass
    try:
        tr.find_element(By.XPATH, '//*[@id="tj"]').click()
    except Exception:
        print('该门课已完成评教')
    wd.close()
    wd.switch_to_window(n[0])
